<template>
  <div id="app">
    <Topbar :key="topbarkey" />
    <Header />
    <router-view @updatekey="updatekey" />
    <Footer />
    <Login v-show="isShowLoginModal" />
    <transition name="slide">
      <Toast v-show="isShowToast" />
    </transition>
  </div>
</template>
<script>
import Topbar from "@/components/Topbar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";
import { JingPinAPI } from "@/request/api.js";
import { mapState } from "vuex";
export default {
  data() {
    return {
      topbarkey: 1,
    };
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        // console.log("app-wacth");
        this.topbarkey++;
      },
    },
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModel.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  async created() {
     //访问环境变量的语法 process.env.变量名
    console.log(process.env.VUE_APP_BASE_URL,process.env.VUE_APP_MY_TEST);
    // this.$axios.get("http://192.168.113.249:8081/cms/products/recommend").then((res)=>{
    //   console.log("res",res);
    // })
    //在request统一管理接口地址
    // request.get('/products/recommend').then((res)=>{
    //   console.log("res",res);
    // })
    //在api.js统一管理接口
    // JingPinAPI().then((res)=>{
    //   console.log("res11",res);
    // })
    let res = await JingPinAPI();
    // console.log("res", res);
  },
  methods: {
    updatekey() {
      this.topbarkey++;
    },
  },
};
</script>

<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
